<template>
  <div class="other-courses">
    <div class="other-courses-content">
      <div class="header">
        <!-- 自定义左右切换按钮 -->
        <div class="title">{{ displayTitle }}</div>
      </div>
      <div class="look-all">
        <span @click="handleAll"> {{ t("homeInformation.viewAll") }} </span>
        <svg-icon name="arrow-right" class="svg-style"></svg-icon>
      </div>

      <!-- 列表 -->
      <div class="list">
        <el-row :gutter="16">
          <el-col :span="8" v-for="(item, index) in dataList" :key="index">
            <div
              class="list-item"
              :data-aos="'fade-left'"
              :data-aos-delay="index * 100"
              v-if="index < 3"
            >
              <div class="list-item-content">
                <img class="image" :src="item.imageUrl" alt="自定义菜单图片" />
                <div class="description">
                  <div class="title">
                    {{ item.menuName }}
                  </div>
                  <div class="time">
                    {{ formatDate(item.createTime) }}
                  </div>
                  <div class="btns">
                    <button @click="goDetail(item.id)">
                      {{ t("homeInformation.detail") }}
                      <svg-icon
                        name="rightArrow"
                        class="arrow-in-btn"
                      ></svg-icon>
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script setup>
import { formatDate } from "~/utils/utils";
const { $navigate } = useNuxtApp();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = defineProps({
  customizationList: {
    type: Array,
    default: [],
  },
  title: {
    type: String,
    default: "",
  },
  listPath: {
    type: String,
    default: "/web/customCourse",
  },
  detailPath: {
    type: String,
    default: "/web/customCourse/detail",
  },
  menuId: {
    type: [String, Number],
    default: "",
  },
  pageName: {
    type: String,
    default: "",
  },
});

const dataList = ref([]);
const displayTitle = computed(() => props.title || t("webBar.customMenu"));
const listPath = computed(() => props.listPath || "/web/customCourse");
const detailPath = computed(() => props.detailPath || "/web/customCourse/detail");
const pageNameLabel = computed(() => props.pageName || displayTitle.value);

watch(
  () => props.customizationList,
  (newVal) => {
    dataList.value = newVal || [];
  },
  { immediate: true, deep: true }
);

const handleAll = () => {
  const query = props.menuId
    ? `?pageName=${encodeURIComponent(pageNameLabel.value)}&id=${props.menuId}`
    : "";
  $navigate(`${listPath.value}${query}`);
};

const goDetail = (id) => {
  const query = [`id=${id}`];
  if (props.menuId) {
    query.push(`menuId=${props.menuId}`, `pageName=${encodeURIComponent(pageNameLabel.value)}`);
  }
  $navigate(`${detailPath.value}?${query.join("&")}`);
};
</script>

<style lang="less" scoped>
.other-courses {
  width: 100%;
  min-height: 100vh;
  background-image: url("~/assets/web/other-bg.png"); // 替换为你的图片路径
  background-size: cover;
  background-position: bottom left; // 改为右上角固定
  background-repeat: no-repeat;

  .other-courses-content {
    width: 100%;
    padding: 185px 110px;
    box-sizing: border-box;

    .header {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .title {
        font-family: PingFang HK, PingFang HK;
        font-weight: 500;
        font-size: 40px;
        color: #ffffff;
        text-align: left;
        position: relative;
        padding-left: 27px;
        line-height: 50px;
        box-sizing: border-box;
      }

      .title::after {
        content: " ";
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 8px;
        height: 50px;
        background: var(--theme-gradient-bg);
      }
    }

    .look-all {
      margin: 20px 0 50px 0;
      font-family: PingFang HK, PingFang HK;
      font-weight: 400;
      font-size: 22px;
      color: var(--el-color-primary);
      text-align: left;
      span {
        cursor: pointer;
      }
      .svg-style {
        font-size: 26px;
      }
    }

    .list {
      width: 100%;
      margin-top: 50px;

      .list-item {
        width: 100%;
        background-color: #ffffff;
        padding-left: 8px;
        border-radius: 0px 0px 24px 0px;

        .list-item-content {
          width: 100%;
          background: #1f2a40;
          border-radius: 0 0 20px 0; // 比父元素大2px
          z-index: 1;

          .image {
            width: 100%;
            aspect-ratio: 1 / 0.6; // 宽高比为1:0.6，即高度为宽度的60%
            object-fit: cover;
          }

          .description {
            width: 100%;
            padding: 20px;
            box-sizing: border-box;

            .title {
              font-family: PingFang HK, PingFang HK;
              font-weight: 600;
              font-size: 20px;
              color: #ffffff;
              text-align: left;
              font-style: normal;
              text-transform: none;
            }

            .time {
              margin: 14px 0 30px 0;
              font-family: PingFang HK, PingFang HK;
              font-weight: 400;
              font-size: 14px;
              color: #6f7683;
              line-height: 20px;
            }

            .btns {
              width: 100%;

              button {
                padding: 10px 40px;
                box-sizing: border-box;
                border-radius: 0px 0px 0px 0px;
                border: 1px solid #ffffff;
                font-family: PingFang HK, PingFang HK;
                font-weight: 400;
                font-size: 14px;
                color: #ffffff;
                position: relative;
                transition: all 0.3s ease;
                cursor: pointer;
                background: transparent;

                &::after {
                  content: "";
                  position: absolute;
                  left: 0;
                  bottom: -1px;
                  width: 0;
                  height: 2px;
                  background: var(--theme-gradient-bg);
                  transition: width 0.3s ease;
                }

                &:hover::after {
                  width: 100%;
                }

                .arrow-in-btn {
                  font-size: 16px;
                  margin-left: 5px;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
